<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>事件代理</title>
    <style>
        .hd{
            border: 2px solid #dddddd;
            background-color: red;
            color: white;
        }

    </style>
</head>
<body>
    <ul>
        <li>hoduunren.com</li>
        <li>hdcms.com</li>
    </ul>
    
    <script>
        'use strict';
        //根据事件代理，可以实现一些东西
        //事件代理是从大往小
        //事件冒泡是从小往大
        const ul = document.querySelector('ul');
        ul.addEventListener('click',() => {
           if(event.target.tagName === 'LI') event.target.classList.toggle('hd');
        });
    </script>
</body>
</html>